//
//  PKRadioHostViewController.m
//  AMomentApp
//
//  Created by lanou on 15/10/7.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "PKRadioHostViewController.h"
#import "PKPlayViewController.h"
#import "UIButton+WebCache.h"
#import "PKRequestManager.h"
#import "PKRadioUserInfoCell.h"
#import "PKRadioDetailModel.h"
#import "PKRadioMainViewController.h"
@interface PKRadioHostViewController () <UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIButton *hostButton;
@property (nonatomic, strong) UILabel *hostNameLabel;
@property (nonatomic, strong) UIButton *originalButton;
@property (nonatomic, strong) UILabel *originalNameLabel;
@property (nonatomic, strong) UILabel *originalRadioLabel;

@end

@implementation PKRadioHostViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    [self showRadioHostInfomation];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((SCREEN_WIDTH-100)/3, (SCREEN_WIDTH-100)/3);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(30, 220, SCREEN_WIDTH-60, (SCREEN_WIDTH-100)/3*2+10) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerClass:[PKRadioUserInfoCell class] forCellWithReuseIdentifier:@"PKRadioUserInfoCell"];
    [self.view addSubview:_collectionView];
    
   // [self.checkButton addTarget:self action:@selector(getBackRadioDetailControl:) forControlEvents:UIControlEventTouchUpInside];
    
    // Do any additional setup after loading the view.
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.hostArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PKRadioUserInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PKRadioUserInfoCell" forIndexPath:indexPath];

    PKRadioDetailModel *hostModel = self.hostArray[indexPath.item];
    [cell.pictureButton sd_setImageWithURL:[NSURL URLWithString:hostModel.coverimg] forState:UIControlStateNormal];
    cell.pictureButton.tag = 100+indexPath.row;
    [cell.pictureButton addTarget:self action:@selector(didClickPictureButton:) forControlEvents:UIControlEventTouchUpInside];
    cell.nameLabel.text = hostModel.title;
    return cell;
}

- (void)didClickPictureButton:(UIButton *)button
{
    PKPlayMoreting *model = self.hostArray[button.tag - 100];
    self.moreWorkBlock(model.tingid);
}

- (void)showRadioHostInfomation
{
    UILabel *hostLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 30, 50, 30)];
    hostLabel.text = @"主播:";
    [self.view addSubview:hostLabel];
    
    _hostButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _hostButton.frame = CGRectMake(90, 30, 30, 30);
    _hostButton.imageView.layer.cornerRadius = 15;
    [_hostButton sd_setImageWithURL:[NSURL URLWithString:self.hostInfoMdeol.playInfo.userinfo.icon] forState:UIControlStateNormal];
    [_hostButton addTarget:self action:@selector(enterAuthorUserInfoControl:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_hostButton];
    
    _hostNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(130, 30, SCREEN_WIDTH-130, 30)];
    _hostNameLabel.text = [NSString stringWithFormat:@"%@",_hostInfoMdeol.playInfo.userinfo.uname];
    [self.view addSubview:_hostNameLabel];

    UILabel *originalLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 80, 50, 30)];
    originalLabel.text = @"原文:";
    [self.view addSubview:originalLabel];
    
    _originalButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _originalButton.frame = CGRectMake(90, 80, 30, 30);
    _originalButton.imageView.layer.cornerRadius = 15;
    [_originalButton sd_setImageWithURL:[NSURL URLWithString:self.hostInfoMdeol.playInfo.authorinfo.icon] forState:UIControlStateNormal];
    [_originalButton addTarget:self action:@selector(enterAuthorUserInfoControl:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_originalButton];
    
    _originalNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(130, 80, SCREEN_WIDTH-130, 30)];
    _originalNameLabel.text = [NSString stringWithFormat:@"%@",_hostInfoMdeol.playInfo.authorinfo.uname];
    [self.view addSubview:_originalNameLabel];
    
    _originalRadioLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 130, SCREEN_WIDTH, 30)];
    _originalRadioLabel.text = [NSString stringWithFormat:@"来自电台: %@",_hostInfoMdeol.radioname];
    [self.view addSubview:_originalRadioLabel];

    UILabel *otherLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 180, SCREEN_WIDTH, 30)];
    otherLabel.text = @"主播其他作品";
    [self.view addSubview:otherLabel];
    
    _checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _checkButton.frame = CGRectMake(SCREEN_WIDTH-120, SCREEN_HEIGHT-180, 100, 30);
    [_checkButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_checkButton setTitle:@"查看全部->" forState:UIControlStateNormal];
    [self.view addSubview:_checkButton];
}

// 更新数据
- (void)UPdateData:(PKPlayModel *)Model array:(NSArray *)array
{
    [_hostButton sd_setImageWithURL:[NSURL URLWithString:Model.playInfo.userinfo.icon] forState:UIControlStateNormal];
    _hostNameLabel.text = Model.playInfo.userinfo.uname;
    [_originalButton sd_setImageWithURL:[NSURL URLWithString:Model.playInfo.authorinfo.icon] forState:UIControlStateNormal];
    _originalNameLabel.text = Model.playInfo.authorinfo.uname;
    _originalRadioLabel.text = [NSString stringWithFormat:@"来自电台: %@",Model.radioname];
    self.hostArray = array;
    [self.collectionView reloadData];
}

- (void)enterAuthorUserInfoControl:(UIButton *)button
{
    NSLog(@"enter");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
